package com.stationpc.dock

import android.graphics.drawable.Drawable
import android.os.Parcel
import android.os.Parcelable

data class AppInfo(
    val packageName: String,
    val name: String,
    val icon: Drawable?,
    var isSelected: Boolean = false,
    var order: Int = 0 // New property to track the app's order
) : Parcelable {
    constructor(parcel: Parcel) : this(
        parcel.readString()!!,
        parcel.readString()!!,
        null,
        parcel.readByte() != 0.toByte(),
        parcel.readInt() // Reading the order from the parcel
    )

    override fun describeContents(): Int {
        return 0
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeString(packageName)
        parcel.writeString(name)
        parcel.writeByte(if (isSelected) 1 else 0)
        parcel.writeInt(order) // Writing the order to the parcel
    }

    companion object CREATOR : Parcelable.Creator<AppInfo> {
        override fun createFromParcel(parcel: Parcel): AppInfo {
            return AppInfo(parcel)
        }

        override fun newArray(size: Int): Array<AppInfo?> {
            return arrayOfNulls(size)
        }
    }
}
